package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC209 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minSubArrayLen(int s, int[] nums) {
            int left = 0, right = 0, curSum = 0, minLength = Integer.MAX_VALUE;
            while (right <= nums.length) {
                while (curSum >= s) {
                    // 缩小窗口
                    minLength = Math.min(minLength, right - left);
                    curSum -= nums[left++];
                }

                // 增大窗口
                if (right == nums.length) break;
                curSum += nums[right++];
            }

            return minLength == Integer.MAX_VALUE ? 0 : minLength;
        }
    }

    public void run() {
        Solution solution = new Solution();
//        int[] arr = InputUtil.toIntegerArray("[]");
        int[] arr = {};
        System.out.println(solution.minSubArrayLen(100, arr));
    }

    public static void main(String[] args) throws Exception {
        LC209 an = new LC209();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
